<?php
namespace app\api\controller;
use app\api\controller\Api;
class Init extends Api
{
    protected $checkaccess = true;
    
    public function initialize() {
        parent::initialize();
        if($this->checkaccess === true) $this->checkAccess();
    }

    /**
     * @return bool|void
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    protected function checkAccess() {
        $token = $this->request->param('token');
        if(empty($token)) {
            return $this->response('站点标识不存在，请联系管理员', [], -99998);
        }
        $this->site = model('site/Site','service')->where('token','=',$token)->find();
        if(empty($this->site)){
            return $this->response('站点标识不存在，请联系管理员', [], -99998);
        }
        if($this->site->deadline != 0 && $this->site->deadline < time()){
            return $this->response('站点标识已过期，请联系管理员', [], -99998);
        }
        if($this->site->status == -1){
            return $this->response('站点标识已被禁用，请联系管理员', [], -99998);
        }
        return true;
    }
}
